// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "XGAudioCaptureSubsystem.generated.h"

class UAudioCapture;
/**
 * 
 */
UCLASS()
class LEARNPLUGIN_API UXGAudioCaptureSubsystem : public UGameInstanceSubsystem,public FTickableGameObject
{
	GENERATED_BODY()
public:
	virtual bool ShouldCreateSubsystem(UObject* Outer) const override;

	/** Implement this for initialization of instances of the system */
	virtual void Initialize(FSubsystemCollectionBase& Collection) override;

	/** Implement this for deinitialization of instances of the system */
	virtual void Deinitialize() override;

protected:
	virtual void Tick(float DeltaTime) override;
	virtual bool IsTickable() const override;
	virtual TStatId GetStatId() const override;

	static void OnAudioGenerated(const float* InAudio, int32 NumSamples);

public:	
	UPROPERTY(BlueprintReadWrite)
	UAudioCapture* AudioCapture = nullptr;

	inline static float* AudioData = nullptr;
	inline static int32 AudioNumSample = -1;
	inline static TArray<float*> InAudios = {};
public :
	// Returns the audio capture device info
UFUNCTION(BlueprintCallable, Category = "AudioCapture")
	bool GetAudioCaptureDeviceInfo(FAudioCaptureDeviceInfo& OutInfo);

	// Starts capturing audio
	UFUNCTION(BlueprintCallable, Category = "AudioCapture")
	void StartCapturingAudio();

	// Stops capturing audio
	UFUNCTION(BlueprintCallable, Category = "AudioCapture")
	void StopCapturingAudio();

	// Returns true if capturing audio
	UFUNCTION(BlueprintCallable, Category = "AudioCapture")
	bool IsCapturingAudio();
};
